#!/bin/bash

DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error {
  echo -e "\\e[91m$1\\e[39m"
  exit 1
}

# Get dependencies
"${DIRECTORY}/pkg-install" "libgl1-mesa-dev libsdl2-dev libvulkan-dev wget unzip" "$(dirname "$0")" || exit 1
cd ~/
rm -f ppsspp_1.12.3_armhf.zip
wget https://github.com/ryanfortner/ppsspp-rpi/releases/download/v1.12.3/ppsspp_0.12.3_armhf.zip || error "Failed to download zip!"
unzip ppsspp_0.12.3_armhf.zip || error "Failed to unzip PPSSPP!"
rm -f ppsspp_0.12.3_armhf.zip || error "Failed to remove zip!"

# Desktop entry
echo "[Desktop Entry]
Version=1.0
Type=Application
Name=PPSSPP
Comment=PSP emulator
Icon=$(dirname "$0")/icon-64.png
Exec=$HOME/ppsspp/PPSSPPSDL
Categories=Game;" > ~/.local/share/applications/ppsspp.desktop || error "Failed to create desktop entry!"

